﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
	Layout = null;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>用户管理</title>
	<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
	<script src="~/lib/jquery/dist/jquery.js"></script>
	<script src="~/lib/layui/layui.js"></script>
</head>
<body>
	<form class="layui-form">
		<div class="layui-form-item">

			<button type="button" class="layui-btn layui-bg-red" onclick="addUser()">+新增</button>
		</div>
	</form>

	<table class="layui-hide" id="ID-table-demo-search"></table>
	<script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>

	<script>
		layui.use(['table', 'form', 'layer'], function () {
			var table = layui.table;
			var form = layui.form;
			var layer = layui.layer;

			// 页面加载时搜索用户
			ShowUsers();
			
			// 查询用户函数
			function ShowUsers() {
				$.ajax({
					url: '@ViewBag.RBACWrite' + "/api/Users/ShowUsers",
					type: 'post',
					data:JSON.stringify({}),
					dataType: "json",
					contentType: "application/json",



					success: res => {
						console.log(res.data);
						table.render({
							elem: '#ID-table-demo-search',
							cols: [[
								{ field: 'userId', width: 120, title: '序号'},
								{ field: 'userName', width: 120, title: '用户名' },
								{ field: 'userStateName', width: 120, title: '状态' },
							]],
							data: res.data,
							page: true,
							limits: [2, 3, 4],
							height: 310
						});
					},


				});
			}
		});
				

		function addUser() {
			location.href = 'AddUser'; // 跳转到添加用户页面
		}
	</script>
</body>
</html>
